package com.qdu.reducer;

import com.qdu.bean.RentCarBean;
import com.qdu.bean.TimeBean;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class RentCarReducer extends Reducer<TimeBean, RentCarBean,TimeBean, RentCarBean> {

    private RentCarBean resultBean = new RentCarBean();

    @Override
    protected void reduce(TimeBean key, Iterable<RentCarBean> values, Context context) throws IOException, InterruptedException {
        int sumcasual = 0;
        int sumregistered = 0;
        int sumcount = 0;

        //1.遍历bean，将casual、registered、count分别累加
        for (RentCarBean rentCarBean:
                values) {
            sumcasual += rentCarBean.getCasual();
            sumregistered += rentCarBean.getRegistered();
            sumcount += rentCarBean.getCount();
        }

        //2.封装对象
        resultBean.set1(sumregistered,sumcasual,sumcount);

        //3.写出
        context.write(key,resultBean);
    }
}
